package io.github.zhibaibubai.zhibaiweb2;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;

@WebServlet(name = "loadDataFromServer", value = "/data/ajax_text.txt")
public class loadDataFromServer implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        servletResponse.setContentType("text/plain");

        PrintWriter writer = servletResponse.getWriter();

        Random random = new Random();
        int randomNumber = random.nextInt(100); // 生成0到99之间的随机数

        writer.write("Hello World " + randomNumber);

        writer.close();
    }

    @Override
    public String getServletInfo() {
        return "";
    }

    @Override
    public void destroy() {

    }
}
